﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Root.master" AutoEventWireup="true" CodeFile="dogdop.aspx.cs" Inherits="Default2" %>

<%@ Register Assembly="DevExpress.Web.v12.2, Version=12.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxFormLayout" TagPrefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Content" runat="Server">
    <script src="../Scripts/toolbar.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        // <![CDATA[
        function OnGetRowValues(values) {
            if (values != null) {
                lbl_NO.SetText('Загрузка нового файла к договору № ' + values);
                Upload.SetClientVisible(true);
            } else { Upload.SetClientVisible(false); }
        }

        function OnGetCodeValues(values) {
            //dogdop_pnl.PerformCallback(values);
            cbPanel.PerformCallback(values);
            grd_dogdop.PerformCallback(values);
        }

        function CreateDoc(value) {
            if (confirm('Вы действительно хотите создать документ внутреннего перемещения?')) {
                clb1.PerformCallback(value);
                grd_Dog.GetRowValues(grd_Dog.GetFocusedRowIndex(), 'CODE', OnGetCodeValues);
            }
        }
        
        function onMenuClick(s, e) {
            switch (e.item.index) {
                case 3:
                    grd_OrderDoc.GetRowValues(grd_OrderDoc.GetFocusedRowIndex(), 'STATE', onComplete);
                    break;
                case 4:
                    state = grd_OrderDoc.GetRowKey(grd_OrderDoc.GetFocusedRowIndex());
                    e.item.NavigateUrl = '~/rep/orderRep.aspx?code=' + state;
                    break;
                default: MenuItemClick(e, grd_OrderDoc);
            }
        }
        function onClick(s, e) {
            switch (e.item.index) {
                case 3:
                    code = grd_dogdop.GetRowKey(grd_dogdop.GetFocusedRowIndex());
                    CreateDoc(code);
                    break;
                default: MenuItemClick(e, grd_dogdop);
            }
        }
        function onChangeRow(values) {
            //OrderDoc_pnl.PerformCallback(values);
            //pnl_menuSpec.PerformCallback(values);
            var item = mMenu.GetItem(3);
            //alert(values);
            switch (values) {
                case 0:
                    item.SetImageUrl('/Images/shared/apply.png');
                    //mMenu.GetItem(3).GetMainElement().title = 'Провести документ';
                    break;
                case 1:
                    item.SetImageUrl('/Images/shared/unapply.png');
                    //mMenu.GetItem(3).GetMainElement().title = 'Отменить проведение документа';
                    break;
                default:
            }
        }

        function onComplete(values) {
            switch (values) {
                case 0:
                    cbk.PerformCallback('1');
                    //onChangeRow(1);
                    grd_OrderDoc.Refresh();
                    mMenu.GetItem(3).SetImageUrl('/Images/shared/unapply.png');
                    //pnl_menuSpec.PerformCallback(1);
                    break;
                case 1:
                    if (confirm('Вы действительно хотите отменить проведение документа?')) {
                        cbk.PerformCallback('0');

                        //onChangeRow(0);
                        grd_OrderDoc.Refresh();
                        mMenu.GetItem(3).SetImageUrl('/Images/shared/apply.png');
                        //pnl_menuSpec.PerformCallback(0);
                    }
                    break;
            }
        }
        // ]]>
    </script>
    <asp:EntityDataSource ID="ds_kontr" runat="server" ConnectionString="name=RegistRar" DefaultContainerName="RegistRar" EnableFlattening="False" EntitySetName="KONTRAGENT" Select="it.[CODE], it.[NAME]">
    </asp:EntityDataSource>
    <div class="pageLabel">
        <dx:ASPxLabel ID="ASPxLabel3" runat="server" Text="Список приложений к договору" Font-Size="Medium" Theme="iOS">
        </dx:ASPxLabel>
    </div>

    <div style="float: left; margin-right: 10px; margin-left: 10px">
        <dx:ASPxMenu ID="ASPxMenu1" runat="server" BackColor="Transparent" EnableViewState="False" EncodeHtml="False" ItemSpacing="1px" 
            SeparatorHeight="15px" SeparatorWidth="2px">
            <ClientSideEvents ItemClick="function(s, e) { onClick(s, e);  }" />
            <SeparatorBackgroundImage ImageUrl="~\Images\shared\ToolBars\Office2003\SeparatorBackground.png" />
            <Items>
                <dx:MenuItem BeginGroup="True" GroupName="grp_edit" Name="btn_Insert" Text="" ToolTip="Добавить запись">
                    <Image Url="~/Images/shared/edit_add.png">
                    </Image>
                </dx:MenuItem>
                <dx:MenuItem GroupName="grp_edit" Name="btn_edit" Text="" ToolTip="Редактировать запись">
                    <Image Url="~/Images/shared/edit.png">
                    </Image>
                </dx:MenuItem>
                <dx:MenuItem GroupName="grp_edit" Name="btn_Delete" Text="" ToolTip="Удалит запись">
                    <Image Url="~/Images/shared/editdelete.png">
                    </Image>
                </dx:MenuItem>
                <dx:MenuItem GroupName="grp_settings" Name="btn_column" Text="" ToolTip="Создать документ внутреннего перемещения">
                    <Image Url="~/Images/shared/format-justify-fill.png">
                    </Image>
                </dx:MenuItem>
            </Items>
        </dx:ASPxMenu>
        <dx:ASPxGridView ID="grd_dogdop" runat="server" AutoGenerateColumns="False" ClientInstanceName="grd_dogdop" DataSourceID="ds_dogdop" KeyFieldName="CODE"
            OnCustomColumnDisplayText="grd_dogdop_CustomColumnDisplayText"
            OnRowDeleting="grd_dogdop_RowDeleting"
            OnRowInserting="grd_dogdop_RowInserting"
            OnStartRowEditing="grd_dogdop_StartRowEditing"
            Width="100%">
            <ClientSideEvents FocusedRowChanged="function(s, e) {grd_OrderDoc.PerformCallback(s.GetFocusedRowIndex());}" />
            <Columns>
                <dx:GridViewCommandColumn ShowInCustomizationForm="True" VisibleIndex="0" Width="20px">
                    <ClearFilterButton Visible="True">
                    </ClearFilterButton>
                </dx:GridViewCommandColumn>
                <dx:GridViewDataTextColumn Caption="Код" FieldName="CODE" ReadOnly="True" ShowInCustomizationForm="True" VisibleIndex="1" Width="40px">
                    <EditFormSettings Visible="False" />
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="DOG" ShowInCustomizationForm="False" Visible="False" VisibleIndex="2">
                    <EditFormSettings Visible="False" />
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Caption="№ доп. согл." FieldName="DOPNUM" ShowInCustomizationForm="True" VisibleIndex="3" Width="80px">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataDateColumn Caption="Дата создания" FieldName="DOPDATE" ShowInCustomizationForm="True" VisibleIndex="4" Width="120px">
                </dx:GridViewDataDateColumn>
                <dx:GridViewDataTextColumn Caption="Примечание" FieldName="NOTE" ShowInCustomizationForm="True" VisibleIndex="5">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn ShowInCustomizationForm="True" VisibleIndex="7" Width="80px">
                    <EditFormSettings Visible="False" />
                    <DataItemTemplate>
                        <a href='dogdoc.aspx?dcod=<%# Eval("CODE") %>&amp;ddog=<%# Eval("DOG") %>' style="color: #000000">документы</a>
                    </DataItemTemplate>
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Caption="вн. перемещение" FieldName="ORDERDOC" ShowInCustomizationForm="True" VisibleIndex="6" Width="80px" Visible="False">
                    <EditFormSettings Visible="False" />
                    <CellStyle HorizontalAlign="Center">
                    </CellStyle>
                </dx:GridViewDataTextColumn>
            </Columns>
            <SettingsBehavior AllowFocusedRow="True" AllowSelectByRowClick="True" AllowSelectSingleRowOnly="True" ConfirmDelete="True" EnableCustomizationWindow="True" />
            <SettingsPager AlwaysShowPager="True" PageSize="5">
                <PageSizeItemSettings Visible="True">
                </PageSizeItemSettings>
            </SettingsPager>
            <SettingsEditing EditFormColumnCount="1" Mode="PopupEditForm" />
            <Settings ShowFilterRow="True" />
            <SettingsLoadingPanel Delay="10" />
            <SettingsPopup>
                <EditForm HorizontalAlign="Center" Width="400px" />
            </SettingsPopup>
        </dx:ASPxGridView>
    </div>

    <div style="float: left; margin-right: 10px; margin-left: 10px">
        <dx:ASPxFormLayout ID="ASPxFormLayout1" runat="server">
            <Items>
                <dx:LayoutGroup Caption="Список накладных">
                    <Items>
                        <dx:LayoutItem Caption="Layout Item" ShowCaption="False">
                            <LayoutItemNestedControlCollection>
                                <dx:LayoutItemNestedControlContainer ID="LayoutItemNestedControlContainer1" runat="server" SupportsDisabledAttribute="True">
                                    <dx:ASPxMenu ID="mMenu" ClientInstanceName="mMenu" runat="server" BackColor="Transparent" ItemSpacing="1px" SeparatorHeight="15px" SeparatorWidth="2px">
                                        <ClientSideEvents ItemClick="function(s, e) { onMenuClick(s, e); }" />
                                        <SeparatorBackgroundImage ImageUrl="~\Images\shared\ToolBars\Office2003\SeparatorBackground.png" />
                                        <Items>
                                            <dx:MenuItem BeginGroup="True" GroupName="grp_edit" Name="btn_Insert" Text="" ToolTip="Добавить запись">
                                                <Image Url="~/Images/shared/edit_add.png">
                                                </Image>
                                            </dx:MenuItem>
                                            <dx:MenuItem GroupName="grp_edit" Name="btn_edit" Text="" ToolTip="Редактировать запись">
                                                <Image Url="~/Images/shared/edit.png" UrlDisabled="~/Images/shared/edit_disable.png">
                                                </Image>
                                            </dx:MenuItem>
                                            <dx:MenuItem GroupName="grp_edit" Name="btn_Delete" Text="" ToolTip="Удалит запись">
                                                <Image Url="~/Images/shared/editdelete.png" UrlDisabled="~/Images/shared/editdelete_disable.png">
                                                </Image>
                                            </dx:MenuItem>
                                            <dx:MenuItem GroupName="grp_settings" Name="btn_column" Text="">
                                                <Image Url="~/Images/shared/apply.png">
                                                </Image>
                                            </dx:MenuItem>
                                            <dx:MenuItem Name="btn_print" Target="_blank" Text="" ToolTip="Печать документа" Visible="False">
                                                <Image Url="~/Images/shared/EXCEL.png">
                                                </Image>
                                            </dx:MenuItem>
                                        </Items>
                                    </dx:ASPxMenu>
                                    <dx:ASPxGridView ID="grd_OrderDoc" ClientInstanceName="grd_OrderDoc" runat="server" AutoGenerateColumns="False" KeyFieldName="CODE"
                                        OnRowInserting="grd_OrderDoc_RowInserting"
                                        OnRowDeleting="grd_OrderDoc_RowDeleting"
                                        OnStartRowEditing="grd_OrderDoc_StartRowEditing"
                                        OnCustomCallback="grd_OrderDoc_CustomCallback">
                                        <ClientSideEvents FocusedRowChanged="function(s, e) {grd_OrderDoc.GetRowValues(grd_OrderDoc.GetFocusedRowIndex(), 'STATE', onChangeRow);}" />
                                        <Columns>
                                            <dx:GridViewDataTextColumn Caption="Код" FieldName="CODE" ReadOnly="True" ShowInCustomizationForm="True" VisibleIndex="1" Width="40px">
                                                <EditFormSettings Visible="False" />
                                                <DataItemTemplate>
                                                    <a href="/doc/orderspec.aspx?id=<%# Eval("CODE") %>" style="color: #000000"><%# Eval("CODE") %></a>
                                                </DataItemTemplate>
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataComboBoxColumn Caption="Статус" FieldName="STATE" ShowInCustomizationForm="True" VisibleIndex="2" Width="80px">
                                                <PropertiesComboBox ValueType="System.Byte">
                                                    <Items>

                                                        <dx:ListEditItem Text="не проведен" Value="0" />

                                                        <dx:ListEditItem Text="проведен" Value="1" />

                                                    </Items>

                                                </PropertiesComboBox>
                                                <EditFormSettings Visible="False" />
                                            </dx:GridViewDataComboBoxColumn>
                                            <dx:GridViewDataDateColumn Caption="Дата документа" FieldName="DOCUMDATE" ShowInCustomizationForm="True" VisibleIndex="3" Width="80px">
                                            </dx:GridViewDataDateColumn>
                                            <dx:GridViewDataComboBoxColumn Caption="Создал" FieldName="OPERATOR" ShowInCustomizationForm="True" VisibleIndex="4" Width="120px">
                                                <PropertiesComboBox DataSourceID="ds_WORKER" TextField="FIO" ValueField="CODE" ValueType="System.Int32">
                                                </PropertiesComboBox>
                                                <EditFormSettings Visible="False" />
                                            </dx:GridViewDataComboBoxColumn>
                                            <dx:GridViewDataComboBoxColumn Caption="Тип операции" FieldName="OPERTYPE" ShowInCustomizationForm="True" VisibleIndex="5" Width="200px">
                                                <PropertiesComboBox ValueType="System.Int32">
                                                    <Items>

                                                        <dx:ListEditItem Text="передача документа в архив" Value="0" />

                                                        <dx:ListEditItem Text="выдача документа из архива" Value="1" />

                                                        <dx:ListEditItem Text="изъятие документа из архива" Value="2" />

                                                    </Items>

                                                </PropertiesComboBox>
                                            </dx:GridViewDataComboBoxColumn>
                                            <dx:GridViewDataComboBoxColumn Caption="Получил документ" FieldName="WORKER" ShowInCustomizationForm="True" VisibleIndex="6" Width="120px">
                                                <PropertiesComboBox DataSourceID="ds_WORKER" TextField="FIO" ValueField="CODE" ValueType="System.Int32">
                                                </PropertiesComboBox>
                                            </dx:GridViewDataComboBoxColumn>
                                            <dx:GridViewDataTextColumn Caption="Примечание" FieldName="NOTE" ShowInCustomizationForm="True" VisibleIndex="8">
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataComboBoxColumn Caption="Объект" FieldName="ARCOBJECT" ShowInCustomizationForm="True" VisibleIndex="7" Width="120px">
                                                <PropertiesComboBox DataSourceID="ds_ArcObject" IncrementalFilteringMode="StartsWith" TextField="NAME" ValueField="CODE" ValueType="System.Int32">
                                                </PropertiesComboBox>
                                            </dx:GridViewDataComboBoxColumn>
                                            <dx:GridViewCommandColumn ShowInCustomizationForm="True" VisibleIndex="0">
                                                <ClearFilterButton Visible="True">
                                                </ClearFilterButton>
                                            </dx:GridViewCommandColumn>
                                        </Columns>
                                        <SettingsBehavior AllowFocusedRow="True" ConfirmDelete="True" EnableCustomizationWindow="true" AllowSelectByRowClick="True" AllowSelectSingleRowOnly="True" />
                                        <SettingsPager AlwaysShowPager="True">
                                            <PageSizeItemSettings Visible="True">
                                            </PageSizeItemSettings>
                                        </SettingsPager>

                                        <Settings ShowFilterRow="True" ShowFooter="True" />
                                    </dx:ASPxGridView>

                                </dx:LayoutItemNestedControlContainer>
                            </LayoutItemNestedControlCollection>
                        </dx:LayoutItem>
                    </Items>
                </dx:LayoutGroup>
            </Items>
        </dx:ASPxFormLayout>

        
    </div>
    <dx:ASPxCallback ID="clb1" runat="server" ClientInstanceName="clb1" OnCallback="clb1_Callback">
        <ClientSideEvents BeginCallback="function(s, e) {loadpanel.Show();}"
            EndCallback="function(s, e) {loadpanel.Hide();}" />
    </dx:ASPxCallback>
    <asp:EntityDataSource ID="ds_dog" runat="server" ConnectionString="name=RegistRar" DefaultContainerName="RegistRar" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="DOG" AutoGenerateWhereClause="True" Where="">
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=RegistRar" DefaultContainerName="RegistRar" EnableFlattening="False" EntitySetName="KONTRAGENT" Select="it.[CODE], it.[NAME]">
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="ds_dogdop" runat="server" ConnectionString="name=RegistRar" DefaultContainerName="RegistRar" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="DOGDOP" Where="" AutoGenerateWhereClause="True">
        <WhereParameters>
            <asp:QueryStringParameter DbType="Int32" DefaultValue="-1" Name="DOG" QueryStringField="id" />
        </WhereParameters>
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="ds_OrderDoc" runat="server" ConnectionString="name=RegistRar" DefaultContainerName="RegistRar" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="ORDERDOC" Where="" AutoGenerateWhereClause="True">
        <WhereParameters>
            <asp:SessionParameter DbType="Int32" Name="DOGDOP" SessionField="DOGDOP" DefaultValue="-1" />
        </WhereParameters>
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="ds_WORKER" runat="server" ConnectionString="name=RegistRar" DefaultContainerName="RegistRar" EnableFlattening="False" EntitySetName="WORKER" Select="it.[CODE], it.[FIO]">
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="ds_ArcObject" runat="server" ConnectionString="name=RegistRar" DefaultContainerName="RegistRar" EnableFlattening="False" EntitySetName="ARCOBJECT">
    </asp:EntityDataSource>
    <dx:ASPxLoadingPanel ID="loadpanel" ClientInstanceName="loadpanel" runat="server" ContainerElementID="ASPxFormLayout1$dogdop_pnl$grd_dogdop" Modal="True" Theme="iOS">
    </dx:ASPxLoadingPanel>
    <dx:ASPxCallback ID="cbk" ClientInstanceName="cbk" runat="server" OnCallback="clb_Callback">
    </dx:ASPxCallback>
</asp:Content>

